package cn.edu.scau.cmi.xuxingao.controller;
/**
 * Sample Skeleton for 'FactoryController.fxml' Controller Class
 */


import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;

public class FactoryController {

    @FXML // ResourceBundle that was given to the FXMLLoader
    private ResourceBundle resources;

    @FXML // URL location of the FXML file that was given to the FXMLLoader
    private URL location;

    @FXML // fx:id="simpleBtn"
    private Button simpleBtn; // Value injected by FXMLLoader

    @FXML // fx:id="factoryBtn"
    private Button factoryBtn; // Value injected by FXMLLoader

    @FXML // fx:id="abstractBtn"
    private Button abstractBtn; // Value injected by FXMLLoader

    @FXML // fx:id="brandTypeCbb"
    private ComboBox brandTypeCbb; // Value injected by FXMLLoader

    @FXML // fx:id="meatTypeCbb"
    private ComboBox meatTypeCbb; // Value injected by FXMLLoader

    @FXML // fx:id="produceBtn"
    private Button produceBtn; // Value injected by FXMLLoader

    @FXML // fx:id="textfield"
    private TextArea textfield; // Value injected by FXMLLoader
    
    private ObservableList<String> brandTypeList = null;
	private ObservableList<String> meatTypeList = null;
	private String mode = "";

	@FXML
    void simpleFactoryMode(ActionEvent event) {
    	meatTypeList = FXCollections.observableArrayList("牛肉","鸡肉","猪肉");
    	brandTypeCbb.setItems(null);
    	meatTypeCbb.setItems(meatTypeList);
    	mode = "简单工厂方法模式";
    }
	
    @FXML
    void factoryMode(ActionEvent event) {
    	meatTypeList = FXCollections.observableArrayList("牛肉","鸡肉","猪肉");
    	brandTypeCbb.setItems(null);
    	meatTypeCbb.setItems(meatTypeList);
    	mode = "工厂方法模式";
    }
    
    @FXML
    void abstractFactoryMode(ActionEvent event) {
    	brandTypeList= FXCollections.observableArrayList("傲农","天邦","温氏");
    	meatTypeList = FXCollections.observableArrayList("牛肉","鸡肉","猪肉");
    	brandTypeCbb.setItems(brandTypeList);
    	meatTypeCbb.setItems(meatTypeList);
    	mode = "抽象工厂模式";
    	
    }
    @FXML
    void produce(ActionEvent event) {
    	String meatTypeString;
    	switch(mode) {
    	case "简单工厂方法模式":
    	{
    		meatTypeString = (String)meatTypeCbb.getValue();
    		cn.edu.scau.cmi.xuxingao.simpleFactoryMethod.domain.Meat meat = null;
    		if(meatTypeString=="牛肉") {
    			meat = cn.edu.scau.cmi.xuxingao.simpleFactoryMethod.MeatFactory.getMeat("beef");
    		}else if(meatTypeString=="鸡肉") {
    			meat = cn.edu.scau.cmi.xuxingao.simpleFactoryMethod.MeatFactory.getMeat("chicken");
    		}else if(meatTypeString=="猪肉"){
    			meat = cn.edu.scau.cmi.xuxingao.simpleFactoryMethod.MeatFactory.getMeat("pork");
    		}else {
    			textfield.setText("请选择您想要的肉类！");
    			break;
    		}
    		textfield.setText(meat.produceString());
    	}
    		break;
    		
    	case "工厂方法模式":
    	{
    		meatTypeString = (String)meatTypeCbb.getValue();
    		cn.edu.scau.cmi.xuxingao.factory.MeatFactory meatfactory = null;
    		if(meatTypeString=="牛肉") {
    			meatfactory = new cn.edu.scau.cmi.xuxingao.factory.BeefFactory();
    		}else if(meatTypeString=="鸡肉") {
    			meatfactory = new cn.edu.scau.cmi.xuxingao.factory.ChickenFactory();
    		}else if(meatTypeString == "猪肉"){
    			meatfactory = new cn.edu.scau.cmi.xuxingao.factory.PorkFactory();
    		}else {
    			textfield.setText("请选择您想要的肉类！");
    			break;
    		}
    		textfield.setText(meatfactory.getMeat().produceString());
    	}
    		break;
    	
    	case "抽象工厂模式":
    	{
    		String brandTypeString = (String)brandTypeCbb.getValue();
    	
    		
    		meatTypeString = (String)meatTypeCbb.getValue();
    		cn.edu.scau.cmi.xuxingao.abstractFactory.factory.MeatFactory meatfactory = null;
    		if(brandTypeString=="傲农") {
    			meatfactory = cn.edu.scau.cmi.xuxingao.abstractFactory.factory.MeatFactory.getFactory("Aonong");
    		}else if(brandTypeString=="天邦") {
    			meatfactory = cn.edu.scau.cmi.xuxingao.abstractFactory.factory.MeatFactory.getFactory("Tianbang");
    		}else if(brandTypeString=="温氏"){
    			meatfactory = cn.edu.scau.cmi.xuxingao.abstractFactory.factory.MeatFactory.getFactory("Wens");
    		}else {
    			textfield.setText("请选择您想要的品牌！");
    			break;
    		}
 
    		cn.edu.scau.cmi.xuxingao.abstractFactory.domainAbstractClass.Meat meat = null;
    		if(meatTypeString == "牛肉") {
    			meat = meatfactory.produceBeef();
    		}else if(meatTypeString == "鸡肉") {
    			meat = meatfactory.produceChicken();
    		}else if(meatTypeString == "猪肉"){
    			meat = meatfactory.producePork();
    		}else {
    			textfield.setText("请选择您想要的肉类！");
    			break;
    		}
    		textfield.setText(meat.introString());
    	}
    		break;
    	default: textfield.setText("请选择工厂模式！");
    	}
    		
    	
    }

  

    @FXML // This method is called by the FXMLLoader when initialization is complete
    void initialize() {
        assert simpleBtn != null : "fx:id=\"simpleBtn\" was not injected: check your FXML file 'FactoryController.fxml'.";
        assert factoryBtn != null : "fx:id=\"factoryBtn\" was not injected: check your FXML file 'FactoryController.fxml'.";
        assert abstractBtn != null : "fx:id=\"abstractBtn\" was not injected: check your FXML file 'FactoryController.fxml'.";
        assert brandTypeCbb != null : "fx:id=\"brandTypeCbb\" was not injected: check your FXML file 'FactoryController.fxml'.";
        assert meatTypeCbb != null : "fx:id=\"meatTypeCbb\" was not injected: check your FXML file 'FactoryController.fxml'.";
        assert produceBtn != null : "fx:id=\"produceBtn\" was not injected: check your FXML file 'FactoryController.fxml'.";
        assert textfield != null : "fx:id=\"textfield\" was not injected: check your FXML file 'FactoryController.fxml'.";

    }
}
